package com.ruoyi.merchant.msg.Model;


import com.ruoyi.merchant.msg.requ.AbstractRequMsg;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * 12上传心率、血压、血氧、血糖（上行协议号：APHP，响应：BPHP）
 */
@Slf4j
@Data
public class APHP extends AbstractRequMsg {
    /**
     * 数据起封包
     */
    public String headCode = "IW";
    /**
     * 协议号
     */
    public final  String funCode = "APHT";
    /**
     * 体温
     */
    private Integer heartRate;
    /**
     * 血压高压 [收缩压]
     */
    private Integer highBloodPressure;
    /**
     * 血压低压 [舒张压]
     */
    private Integer lowBloodPressure;
    /**
     * 血氧
     */
    private Integer bloodOxygen;
    /**
     * 血糖
     */
    private Float bloodSugar;
    /**
     * 体温
     */
    private Float temperature;
    /**
     * 结尾封包
     */
    public String footCode = "#";


     public APHP(){}

    /**
     * IWAP50,36.7,90#
     * @param cmdStr
     */
    public APHP(String cmdStr)
    {
        String[] split = cmdStr.split(",");
        if (split[0].equals("IWAPHP"))
        {
            if (StringUtils.isNoneBlank(split[1])){
                this.heartRate = Integer.valueOf(split[1]);
            }

            if (StringUtils.isNoneBlank(split[2])){
                this.highBloodPressure = Integer.valueOf(split[2]);
            }


            if (StringUtils.isNoneBlank(split[3])){
                this.lowBloodPressure = Integer.valueOf(split[3]);
            }

            if (StringUtils.isNoneBlank(split[4])){
                this.bloodOxygen = Integer.valueOf(split[4]);
            }

            if (StringUtils.isNoneBlank(split[5])){
                this.bloodSugar = Float.valueOf(split[5]);
            }

            String replace = split[6].replace("#", "");
            if (StringUtils.isNoneBlank(replace)){
                this.temperature = Float.valueOf(replace);
            }
        }
        else {
            log.error("协议格式错误:{}",cmdStr);
        }

    }



}
        



